package com.xgggh.redpack.ui.home.viewbinder;

import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import com.jakewharton.rxbinding3.view.RxView;
import com.xgggh.redpack.R;
import com.xgggh.redpack.base.viewbinder.BaseItemViewBinder;
import com.xgggh.redpack.base.viewbinder.BinderViewHolder;
import com.xgggh.redpack.databinding.ContentHomeItemBinding;
import com.xgggh.redpack.domain.redpack.Pack;
import com.xgggh.redpack.ui.profile.PersonalActivity;
import com.xgggh.redpack.ui.redpack.OpenRedPackActivity;
import io.reactivex.Observable;


public class HomeViewBinder extends BaseItemViewBinder<Pack> {

    @Override
    protected void onBindViewHolder(@NonNull BinderViewHolder holder, @NonNull Pack item) {
        super.onBindViewHolder(holder,item);
        ContentHomeItemBinding binding= DataBindingUtil.getBinding(holder.itemView);
        binding.setItem(item);
       /* DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(item.getProfile().getHeadFile())
                .setAutoPlayAnimations(true)
                .build();*/
       if (item.getProfile()!=null && !TextUtils.isEmpty(item.getProfile().getHeadFile())){
           binding.header.setImageURI(item.getProfile().getHeadFile());
       }

        RxView.clicks(binding.itemParent)
               // .as(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(this)))
                .subscribe(o -> {
                    startActivity(holder.itemView.getContext(),OpenRedPackActivity.class,binding.getItem());
                });
        Observable.merge(RxView.clicks(binding.header),RxView.clicks(binding.name),RxView.clicks(binding.slogan))
                //.compose(uiTransformer())
                .subscribe(o -> {
                    startActivity(holder.itemView.getContext(),PersonalActivity.class,binding.getItem());
                });

    }

    @NonNull
    @Override
    public int getResId() {
        return R.layout.content_home_item;
    }
}
